package com.hundsun.cprs.yyt.util;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.hundsun.cprs.yyt.service.system.SystemConfigProperties;

/**
 * 简单实现控制表单属性使能的功能
 * @author linrl
 * @date 2018年12月16日
 */
public class FormFieldUtil {
    
    private ApplicationContext context;
    
    private SystemConfigProperties systemConfig;
    
    public void init(Object obj){
        this.context = WebApplicationContextUtils.findWebApplicationContext((ServletContext)obj);
        this.systemConfig = context.getBean(SystemConfigProperties.class);
    }
    
    public boolean isEnable(String key){
        Object property = BeanUtils.getProperty(systemConfig, key);
        if (property == null) {
            return false;
        }
        try {
            boolean result = Boolean.valueOf((String)property);
            return result;
        } catch (Exception e) {
            return false;
        }
    }
}
